package com.gombe.credit.app.ui.adapter

import androidx.recyclerview.widget.RecyclerView
import com.gombe.credit.app.R
import com.gombe.credit.app.utils.GombeCreditImageLoader
import com.gombe.credit.lib.adapter.GombeCreditRecyclerViewAdapter
import com.gombe.credit.lib.adapter.GombeCreditViewHolderHelper
import com.gombe.credit.lib.shapeview.layout.GombeCreditConstraintLayout
import org.json.JSONObject

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2025/3/25 18:36
 * @Annotation：
 */
class AdapterGombeCreditStepWalletType(recyclerView: RecyclerView?) : GombeCreditRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.dialog_gombe_credit_step_wallet_type_item) {
    override fun setItemChildListener(helper: GombeCreditViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.walletTypeLayout) //点击Item
    }
    override fun fillData(helper: GombeCreditViewHolderHelper, position: Int, model: JSONObject) {
        val isSelect = model.optBoolean("isSelect", false)
        val walletTypeLayout = helper.getView<GombeCreditConstraintLayout>(R.id.walletTypeLayout)
        val imgWalletTypeLogo = helper.getImageView(R.id.imgWalletTypeLogo)
        val textWalletTypeTitle = helper.getTextView(R.id.textWalletTypeTitle)
        textWalletTypeTitle.text = model.optString("desc")
        GombeCreditImageLoader.instance?.loadImageUrl(mContext,imgWalletTypeLogo,model.optString("logo"), R.mipmap.gombe_credit_image_holder)

        val imgWalletTypeSelected = helper.getImageView(R.id.imgWalletTypeSelected)
        if (isSelect) {
            walletTypeLayout.shapeDrawableBuilder
                .setStrokeColor(getColor(R.color.theme))
                .setSolidColor(getColor(R.color.gombe_credit_fffff5b5))
                .intoBackground()
            textWalletTypeTitle.setTextColor(getColor(R.color.gombe_credit_ff1d1e20))
            imgWalletTypeSelected.setImageResource(R.mipmap.gombe_credit_image_step_ocr_type_selected_icon)
        } else {
            walletTypeLayout.shapeDrawableBuilder
                .setStrokeColor(getColor(R.color.gombe_credit_FFF9F9F7))
                .setSolidColor(getColor(R.color.gombe_credit_FFF9F9F7))
                .intoBackground()
            textWalletTypeTitle.setTextColor(getColor(R.color.gombe_credit_ffa8a8a8))
            imgWalletTypeSelected.setImageResource(R.mipmap.gombe_credit_image_step_ocr_type_normal_icon)
        }
    }
}